<template>
	<view class="outer-container">
		<uni-nav-bar statusBar="true"
			shadow="true"
			backgroundColor="#e8b768"
			color="#fff"
			title="VIP会员">
		</uni-nav-bar>

		<scroll-view scroll-x="true"
			enable-flex
			class="nav-scroll"
			:scroll-into-view="'nav'+navId"
			scroll-with-animation>
			<view v-for="(item, index) in navItems"
				:key="item"
				:id="'nav'+index"
				:class="['nav-item', {active: navId == index}]"
				@tap="handleTapNavItem">
				{{item}}
			</view>
		</scroll-view>

		<view class="vip-card"
			v-if="!userInfo || !userInfo.vip">
			<image class="bg-img"
				src="../../static/img/vip/juxing98.png"
				mode=""></image>
			<view class="top-content"
				@tap="toMyVip">
				<view class="top-row">
					<view class="left">

						<image v-if="!userInfo"
							src="../../static/img/vip/zu431.png"></image>
						<image v-else
							:src="userInfo.avatarUrl"></image>
					</view>

					<view class="right">
						<template v-if="!userInfo">
							<view class="header">
								<text>欢迎你, 新朋友</text>
								<view class="open-act">
									开通
								</view>
							</view>
							<text style="color: #fff;">8元开通VIP, 畅学明初独家菜谱</text>
						</template>

						<template v-else>
							<view class="header">
								<text>{{userInfo.nickName}}</text>
								<view class="open-act">
									开通
								</view>
							</view>
							<text style="color: #fff;">8元开通VIP, 畅学明初独家菜谱</text>
						</template>




					</view>
				</view>


			</view>
			<view class="bottom-content">
				<view class="bottom-item">
					<image src="../../static/img/vip/mengbanzu254.png"
						mode=""></image>
					<text>名厨课堂</text>
				</view>

				<view class="bottom-item">
					<image src="../../static/img/vip/mengbanzu255.png"
						mode=""></image>
					<text>无广告打扰</text>
				</view>

				<view class="bottom-item">
					<image src="../../static/img/vip/mengbanzu256.png"
						mode=""></image>
					<text>身份标识</text>
				</view>

			</view>
		</view>

		<scroll-view scroll-y="true"
			enable-flex
			class="main-menu"
			:scroll-into-view="mainNavId"
			scroll-with-animation>


			<view id="nav0" class="main-wrap">
				<heading title="VIP最新推荐"></heading>
				<menu-scroll :itemList="menus"
					:isVip="true"></menu-scroll>
			</view>

			<view id="nav1" class="main-wrap">
				<heading title="限时免费体验"></heading>
				<menu-scroll :itemList="freeMenuList"></menu-scroll>
			</view>


			<view id="nav2" class="main-wrap">
				<template v-if="userInfo.vip">
					<heading title="精品名厨(会员专享)"></heading>
					<menu-scroll :itemList="vipExclusiveMenu"
						:isVip="true"></menu-scroll>
				</template>
			</view>

			<view id="nav3" class="main-wrap">
				<heading title="猜你喜欢"></heading>
				<menu-grid :itemList="likeMenu"></menu-grid>
			</view>


		</scroll-view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: null,
				navId: 0,
				mainNavId: '',
				navItems: ['VIP精品推荐', '限时免费体验', '精品名厨', '猜你喜欢'],
				menus: [],
				freeMenuList: [],
				likeMenu: [],
				vipExclusiveMenu: []
			}
		},
		onLoad() {

			this.userInfo = getApp().globalData.userInfo;
			this.getRecommendMenuList();
			this.getIsFreeMenuList();
			this.getLikeMenu();
		},
		onShow() {
			this.userInfo = getApp().globalData.userInfo;
			this.getVipExclusive();
			// console.log(this.userInfo);
		},
		// computed:{
		// 		userInfo(){
		// 			console.log(111);
		// 			return getApp().globalData.userInfo;
		// 		}
		// },
		methods: {
			toMyVip() {
				uni.navigateTo({
					url: '/pages/my-vip/my-vip'
				})
			},
			handleTap(e) {
				console.log(e);
			},
			handleTapNavItem(e) {
				this.navId = e.currentTarget.id.substr(-1);
				this.mainNavId = 'nav'+e.currentTarget.id.substr(-1);
				console.log(this.mainNavId);
			},
			async getRecommendMenuList() {
				let { menus } = await this.$api.vipMember.getRecommendMenuList();
				this.menus = menus;
				// console.log(this.menus);
			},
			async getIsFreeMenuList() {
				let { menus } = await this.$api.vipMember.getisFreeMenuList();
				this.freeMenuList = menus;
				// console.log(this.freeMenuList);
			},
			async getLikeMenu() {
				let { menus } = await this.$api.vipMember.getlikeMenu();
				this.likeMenu = menus;
			},

			async getVipExclusive() {
				let { menus } = await this.$api.vipMember.getVipExclusive();
				this.vipExclusiveMenu = menus;
				// console.log(this.vipExclusiveMenu);
			}
		}
	}
</script>

<style style
	lang="scss"
	scoped>
	.outer-container {
		width: 100vw;
		height: 100vh;
	}

	.nav-scroll {
		display: flex;
		height: 60rpx;
		white-space: nowrap;
		padding: 20rpx 0;

		.nav-item {
			padding: 0 30rpx;
			font-size: 28rpx;
			height: 60rpx;
			line-height: 60rpx;
			box-sizing: border-box;
		}

		.active {
			font-size: large;
			font-weight: bold;
		}
	}

	.vip-card {
		position: relative;
		width: 686rpx;
		height: 324rpx;
		margin: 0 auto;

		.bg-img {
			width: 100%;
			height: 100%;
			border-radius: 16rpx;
		}

		.top-content {
			position: absolute;
			top: 0;
			left: 0;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: calc(324rpx - 96rpx);
			box-sizing: border-box;

			.top-row {
				display: flex;
				align-items: center;
				width: 650rpx;

				.left {
					width: 126rpx;

					image {
						width: 100%;
						height: 132rpx;
						margin-right: 20rpx;
						border-radius: $uni-border-radius-circle;
						border: 8rpx solid #fff;
					}
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: space-evenly;
					width: calc(622rpx - 126rpx);
					height: 132rpx;
					box-sizing: border-box;
					padding: 0 20rpx;


					.header {
						display: flex;
						justify-content: space-between;

						text {
							font-size: 26rpx;
							color: #848486;
						}

						.open-act {
							width: 108rpx;
							height: 34rpx;
							color: #7a4524;
							font-size: 26rpx;
							text-align: center;
							background-image: url(../../static/img/vip/juxing221.png);
							background-repeat: no-repat;
							background-position: center center;

						}
					}
				}
			}


		}

		.bottom-content {
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 96rpx;
			border-radius: 16rpx;
			box-sizing: border-box;
			padding: 0 40rpx;
			background-image: url(../../static/img/vip/juxing238.png);
			background-repeat: no-repeat;
			background-position: center center;

			.bottom-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				width: max-content;

				image {
					width: 40rpx;
					height: 40rpx;
				}

				text {
					font-size: 24rpx;
					color: #d3b99a;
				}
			}
		}

	}

	.main-menu {
		width: 100vw;
		height: 100%;
		/* height: 100%; */
		white-space: nowrap;
		display: flex;
		flex-direction: column;
		align-items: center;
		.main-wrap{
			width: 100vw;
			/* height: fit-content; */
			max-height: 1200rpx;
		}
	}
</style>
